<?php

/**
 * This is the model class for table "member_code".
 *
 * The followings are the available columns in table 'member_code':
 * @property string $code
 * @property integer $user_id
 * @property string $courses_id
 * @property integer $status
 * @property string $create_at
 * @property integer $active
 *
 * The followings are the available model relations:
 * @property Education[] $educations
 * @property Courses $courses
 * @property Member $user
 */
class MemberCodeBase extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return MemberCodeBase the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'member_code';
	}

	public function primaryKey() {
		return 'code';
	}
	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('code, user_id, courses_id, status', 'required'),
			array('user_id, status, active', 'numerical', 'integerOnly'=>true),
			array('code', 'length', 'max'=>10),
			array('courses_id', 'length', 'max'=>11),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('code, user_id, courses_id, status, create_at, active', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'educations' => array(self::HAS_MANY, 'Education', 'code_id'),
			'courses' => array(self::BELONGS_TO, 'Courses', 'courses_id'),
//			'member' => array(self::BELONGS_TO, 'Member', 'user_id'),
//			'user' => array(self::BELONGS_TO, 'Users', 'user_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'code' => 'Code',
			'user_id' => 'User',
			'courses_id' => 'Courses',
			'status' => 'Status',
			'create_at' => 'Create At',
			'active' => 'Active',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('code',$this->code,true);
		$criteria->compare('user_id',$this->user_id);
		$criteria->compare('courses_id',$this->courses_id,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('create_at',$this->create_at,true);
		$criteria->compare('active',$this->active);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}